package com.wrh.draw;

import com.wrh.draw.bean.LonLat;

import java.awt.*;

/**
 * @author wrh
 */
public class LonLatConverter {

    private int imgWidth;
    private int imgHeight;
    private double lonMin;
    private double lonMax;
    private double latMin;
    private double latMax;

    private double lonLength;
    private double latLength;

    public LonLatConverter(int imgWidth, int imgHeight, double lonMin, double lonMax, double latMin, double latMax) {
        this.imgWidth = imgWidth;
        this.imgHeight = imgHeight;
        this.lonMin = lonMin;
        this.lonMax = lonMax;
        this.latMin = latMin;
        this.latMax = latMax;

        this.lonLength = lonMax - lonMin;
        this.latLength = latMax - latMin;
    }


    public Point lonLatToPoint(LonLat lonLat) {
        return lonLatToPoint(lonLat.getLon(),lonLat.getLat());
    }

    public Point lonLatToPoint(double lon,double lat) {
        Point point = new Point();
        double x = Math.round(((lon- lonMin) / lonLength) * imgWidth);
        double y = Math.round(((latMax - lat) / latLength) * imgHeight);
        point.setLocation(x, y);
        return point;
    }

}
